package stsj.meddroid.elements;

import stsj.meddroid.Settings;
import stsj.meddroid.screen.BattleScreen;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;

public class MedDroid {

	
	public boolean hit = false;
	public static final int MAX_HP = 100;
	public static final int MAX_ENERGY = 100;
	public static final int MPUNCH = 0;
	public static final int MLASER = 1;
	public static final int MSPECIAL = 2;
	public static final int MSHIELD = 3;
	public static final int MINVISIBLE = 4;
	public static final int MBELUMTAHU = 5;	
	public static final int MIMPERIAL = 6;
	public int temp;
	public int face;
	public int energy;
	public int health;
	public int state; // (BALL, MEDDROID, SLEEP)
	public int x;
	public int y;
	public int countSpecial = 0;
	public int special = 0;
	public int punch = 0;
	public int laser = 0;
	public int mode;
	public int countDamage = 0;
	
	public boolean modeShieldUnlocked;
	public boolean modeInvisibleUnlocked;
	public boolean modeBelumTahuUnlocked;
	public boolean modeImperialUnlocked;
	
	public boolean shieldOn;
	public boolean invisibleOn;
	public boolean belumTahuOn;	
	
	public Rectangle playerRec;
	public Rectangle punchArea;
	public Pixmap arena;

	public MedDroid() {
		energy = 100;
		health = 100;
		state = BattleScreen.NORMAL;
		face = BattleScreen.FRONT;
		x = 0;
		y = 0;
		arena = BattleScreen.arena;
		playerRec = new Rectangle(228,140, 24, 40);
		punchArea = new Rectangle(0,0,45,56);
		
		modeShieldUnlocked = Settings.modeShieldUnlocked;
		modeInvisibleUnlocked = Settings.modeInvisibleUnlocked;
		modeBelumTahuUnlocked = Settings.modeBelumTahuUnlocked;
		modeImperialUnlocked = Settings.modeImperialUnlocked;
		shieldOn = false;
		invisibleOn = false;
		belumTahuOn = false;
	}

	public MedDroid(int Health, int Energy,  int x, int y) {
		energy = Energy;
		health = Health;
		state = BattleScreen.NORMAL;
		face = BattleScreen.FRONT;
		this.x = x;
		this.y = y;
		arena = BattleScreen.arena;
		playerRec = new Rectangle((Gdx.graphics.getWidth()/2)-12,((Gdx.graphics.getHeight()-60)/2)-20, 24, 40);
		punchArea = new Rectangle(0,0,34,56);
		

//		modeShieldUnlocked = false;
//		modeInvisibleUnlocked = false;
//		modeBelumTahuUnlocked = false;
//		modeImperialUnlocked = false;
		modeShieldUnlocked = Settings.modeShieldUnlocked;
		modeInvisibleUnlocked = Settings.modeInvisibleUnlocked;
		modeBelumTahuUnlocked = Settings.modeBelumTahuUnlocked;
		modeImperialUnlocked = Settings.modeImperialUnlocked;
		shieldOn = false;
		invisibleOn = false;
		belumTahuOn = false;
		
	}

	public boolean isExistEnemy(){
		for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
			if (enemy.x+enemy.mySprite.getWidth() > BattleScreen.centerX-240 && enemy.x < BattleScreen.centerX+240){
				if (enemy.y+enemy.mySprite.getHeight() > (Gdx.graphics.getHeight()/2)-160 && enemy.y < (Gdx.graphics.getHeight()/2)+160){ return true;}
			}
		}
	return false;
	}
	
	// move perlu validasi kembali..

	public void moveRight() {
		if (state != BattleScreen.PUNCH){face = BattleScreen.RIGHT;}
		state = BattleScreen.MOVE;
		String hex1, hex2;
		hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x + 1 + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight() - (int)playerRec.y - (int)playerRec.getHeight() + BattleScreen.resolutionProblemSolver));
		hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x + 1 + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight() - (int)playerRec.y + BattleScreen.resolutionProblemSolver));
		boolean b = false;
		if (hex1.length() == 8 && hex2.length() == 8) {
			if (hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
					&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
					&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a') {
				x = x + 2;			
				for (Orb orb : BattleScreen.listOfOrb){
					orb.moveLeft(2);
				}
				BattleScreen.kidney1.moveLeft(2);
				BattleScreen.kidney2.moveLeft(2);
				BattleScreen.brain.moveLeft(2);
				BattleScreen.lung.moveLeft(2);
				BattleScreen.liver.moveLeft(2);
//				 Move All Enemies
				for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
					enemy.decX();
					enemy.decX();
					if (enemy instanceof BlueRepetol){BlueRepetol.se -= 2;}
					if (enemy instanceof RedRepetol){RedRepetol.se -= 2;}
					if (enemy instanceof VioletRepetol){VioletRepetol.se -= 2;}
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
					}
				}
				for (Vaccine vaccine : BattleScreen.listOfVaccines){
					vaccine.moveLeft(2);
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
					}
				}
				hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x + 1 + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight() - (int)playerRec.y - (int)playerRec.getHeight() + BattleScreen.resolutionProblemSolver));
				hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x + 1 + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight() -(int)playerRec.y + BattleScreen.resolutionProblemSolver));
				while (!(hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
						&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
						&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a')
						|| b) {
					x--;
					for (Orb orb : BattleScreen.listOfOrb){
						orb.moveRight(1);
					}
					BattleScreen.kidney1.moveRight(1);
					BattleScreen.kidney2.moveRight(1);
					BattleScreen.brain.moveRight(1);
					BattleScreen.lung.moveRight(1);
					BattleScreen.liver.moveRight(1);
//					Move All Enemies
					b = false;
					for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
						enemy.incX();
						if (enemy instanceof BlueRepetol){BlueRepetol.se += 1;}
						if (enemy instanceof RedRepetol){RedRepetol.se += 1;}
						if (enemy instanceof VioletRepetol){VioletRepetol.se += 1;}
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
						}
					}
					for (Vaccine vaccine : BattleScreen.listOfVaccines){
						vaccine.moveRight(1);
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
						}
					}
					hex1 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x+ 1 + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y - (int) playerRec.getHeight() + BattleScreen.resolutionProblemSolver));
					hex2 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x+ 1 + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y + BattleScreen.resolutionProblemSolver));
				}
			}
		}
		for (Orb orb : BattleScreen.listOfOrb){
			if (Intersector.intersectRectangles(playerRec, orb.getCoreRectangle())){
				orb.eaten(this);
			}
		}
	}

	public void moveLeft() {
		if (state != BattleScreen.PUNCH){face = BattleScreen.LEFT;}
		state = BattleScreen.MOVE;
		String hex1, hex2;
		hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x- 1, y + Gdx.graphics.getHeight()-(int)playerRec.y - (int)playerRec.getHeight() + BattleScreen.resolutionProblemSolver));
		hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x- 1, y + Gdx.graphics.getHeight()-(int)playerRec.y + BattleScreen.resolutionProblemSolver));
		boolean b = false;
		if (hex1.length() == 8 && hex2.length() == 8) {
			if (hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
					&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
					&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a') {
				x = x - 2;
				for (Orb orb : BattleScreen.listOfOrb){
					orb.moveRight(2);
				}
				BattleScreen.kidney1.moveRight(2);
				BattleScreen.kidney2.moveRight(2);
				BattleScreen.brain.moveRight(2);
				BattleScreen.lung.moveRight(2);
				BattleScreen.liver.moveRight(2);
//				Move All Enemies
				for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
					enemy.incX();
					enemy.incX();
					if (enemy instanceof BlueRepetol){BlueRepetol.se += 2;}
					if (enemy instanceof RedRepetol){RedRepetol.se += 2;}
					if (enemy instanceof VioletRepetol){VioletRepetol.se += 2;}
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
					}
				}
				for (Vaccine vaccine : BattleScreen.listOfVaccines){
					vaccine.moveRight(2);
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
					}
				}
				hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x- 1, y + Gdx.graphics.getHeight()-(int)playerRec.y - (int)playerRec.getHeight() + BattleScreen.resolutionProblemSolver));
				hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x- 1, y + Gdx.graphics.getHeight()-(int)playerRec.y + BattleScreen.resolutionProblemSolver));
				while (!(hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
						&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
						&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a')
						|| b) {
					x++;
					for (Orb orb : BattleScreen.listOfOrb){
						orb.moveLeft(1);
					}
					BattleScreen.kidney1.moveLeft(1);
					BattleScreen.kidney2.moveLeft(1);
					BattleScreen.brain.moveLeft(1);
					BattleScreen.lung.moveLeft(1);
					BattleScreen.liver.moveLeft(1);
//					Move All Enemies
					b = false;
					for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
						enemy.decX();
						if (enemy instanceof BlueRepetol){BlueRepetol.se -= 1;}
						if (enemy instanceof RedRepetol){RedRepetol.se -= 1;}
						if (enemy instanceof VioletRepetol){VioletRepetol.se -= 1;}
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
						}
					}
					for (Vaccine vaccine : BattleScreen.listOfVaccines){
						vaccine.moveLeft(1);
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
						}
					}
					hex1 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x- 1, y + Gdx.graphics.getHeight()-(int)playerRec.y - (int)playerRec.getHeight()+ BattleScreen.resolutionProblemSolver));
					hex2 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x- 1, y + Gdx.graphics.getHeight()-(int)playerRec.y + BattleScreen.resolutionProblemSolver));
				}
			}
		}
		for (Orb orb : BattleScreen.listOfOrb){
			if (Intersector.intersectRectangles(playerRec, orb.getCoreRectangle())){
				orb.eaten(this);
			}
		}
	}

	public void moveUp() {
		if (face == BattleScreen.FRONT) {
			face = BattleScreen.RIGHT;
		}
		state = BattleScreen.MOVE;
		String hex1, hex2;
		hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x, y + Gdx.graphics.getHeight()-(int)playerRec.y-(int)playerRec.getHeight() - 1 + BattleScreen.resolutionProblemSolver));
		hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y-(int)playerRec.getHeight() - 1 + BattleScreen.resolutionProblemSolver));
		boolean b = false;
		if (hex1.length() == 8 && hex2.length() == 8) {
			if (hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
					&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
					&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a') {
				y = y - 2;
				for (Orb orb : BattleScreen.listOfOrb){
					orb.moveDown(2);
				}
				BattleScreen.kidney1.moveDown(2);
				BattleScreen.kidney2.moveDown(2);
				BattleScreen.brain.moveDown(2);
				BattleScreen.lung.moveDown(2);
				BattleScreen.liver.moveDown(2);
//				Move All Enemies
				for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
					enemy.decY();
					enemy.decY();
					if (enemy instanceof BlueRepetol){BlueRepetol.ye -= 2;}
					if (enemy instanceof RedRepetol){RedRepetol.ye -= 2;}
					if (enemy instanceof VioletRepetol){VioletRepetol.ye -= 2;}
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
					}
				}
				for (Vaccine vaccine : BattleScreen.listOfVaccines){
					vaccine.moveDown(2);
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
					}
				}
				hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x, y + Gdx.graphics.getHeight()-(int)playerRec.y-(int)playerRec.getHeight() + 1 + BattleScreen.resolutionProblemSolver));
				hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x +(int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y-(int)playerRec.getHeight()+ 1 + BattleScreen.resolutionProblemSolver));
				while (!(hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
						&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
						&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a')
						|| b) {
					y++;
					for (Orb orb : BattleScreen.listOfOrb){
						orb.moveUp(1);
					}
					BattleScreen.kidney1.moveUp(1);
					BattleScreen.kidney2.moveUp(1);
					BattleScreen.brain.moveUp(1);
					BattleScreen.lung.moveUp(1);
					BattleScreen.liver.moveUp(1);
//					Move All Enemies
					b = false;
					for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
						enemy.incY();
						if (enemy instanceof BlueRepetol){BlueRepetol.ye += 1;}
						if (enemy instanceof RedRepetol){RedRepetol.ye += 1;}
						if (enemy instanceof VioletRepetol){VioletRepetol.ye += 1;}
						
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
						}
					}
					for (Vaccine vaccine : BattleScreen.listOfVaccines){
						vaccine.moveUp(1);
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
						}
					}
					hex1 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x, y + Gdx.graphics.getHeight()-(int)playerRec.y-(int)playerRec.getHeight() - 1 + BattleScreen.resolutionProblemSolver));
					hex2 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y-(int)playerRec.getHeight()- 1 + BattleScreen.resolutionProblemSolver));
				}
			}
		}
		for (Orb orb : BattleScreen.listOfOrb){
			if (Intersector.intersectRectangles(playerRec, orb.getCoreRectangle())){
				orb.eaten(this);
			}
		}

	}

	public void moveDown() {
		if (face == BattleScreen.FRONT) {
			face = BattleScreen.LEFT;
		}
		state = BattleScreen.MOVE;
		String hex1, hex2, hex3; // Penanganan kasus pantat
		hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x, y + Gdx.graphics.getHeight()-(int)playerRec.y+ 1 + BattleScreen.resolutionProblemSolver));
		hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x +(int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y+ 1 + BattleScreen.resolutionProblemSolver));
		hex3 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x +(int)(playerRec.getWidth()/2), y + Gdx.graphics.getHeight()-(int)playerRec.y+ 1 + BattleScreen.resolutionProblemSolver));
		boolean b = false;
		if (hex1.length() == 8 && hex2.length() == 8 && hex3.length() == 8) {
			if (hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
					&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
					&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a'
					&& hex3.charAt(0) > 'a' && hex3.charAt(2) > 'a'
					&& hex3.charAt(4) > 'a') {
				y = y + 2;
				BattleScreen.kidney1.moveUp(2);
				BattleScreen.kidney2.moveUp(2);
				BattleScreen.brain.moveUp(2);
				BattleScreen.lung.moveUp(2);
				BattleScreen.liver.moveUp(2);
				for (Orb orb : BattleScreen.listOfOrb){
					orb.moveUp(2);
				}
				//				Move All Enemies
				for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
					enemy.incY();
					enemy.incY();
					if (enemy instanceof BlueRepetol){BlueRepetol.ye += 2;}
					if (enemy instanceof RedRepetol){RedRepetol.ye += 2;}
					if (enemy instanceof VioletRepetol){VioletRepetol.ye += 2;}
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
					}
				}
				for (Vaccine vaccine : BattleScreen.listOfVaccines){
					vaccine.moveUp(2);
					if (!b) {
						b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
					}
				}
				hex1 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x, y + Gdx.graphics.getHeight()-(int)playerRec.y+ 1 + BattleScreen.resolutionProblemSolver));
				hex2 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x +(int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y+ 1 + BattleScreen.resolutionProblemSolver));
				hex3 = Integer.toHexString(arena.getPixel(x + (int)playerRec.x +(int)(playerRec.getWidth()/2), y + Gdx.graphics.getHeight()-(int)playerRec.y+ 1 + BattleScreen.resolutionProblemSolver));
				while (!(hex1.charAt(0) > 'a' && hex1.charAt(2) > 'a'
						&& hex1.charAt(4) > 'a' && hex2.charAt(0) > 'a'
						&& hex2.charAt(2) > 'a' && hex2.charAt(4) > 'a'
						&& hex3.charAt(0) > 'a' && hex3.charAt(2) > 'a' 
						&& hex3.charAt(4) > 'a')
						|| b) {	
					y--;
					for (Orb orb : BattleScreen.listOfOrb){
						orb.moveDown(1);
					}
					BattleScreen.kidney1.moveDown(1);
					BattleScreen.kidney2.moveDown(1);
					BattleScreen.brain.moveDown(1);
					BattleScreen.lung.moveDown(1);
					BattleScreen.liver.moveDown(1);
					b = false;
					for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
						enemy.decY();
						if (enemy instanceof BlueRepetol){BlueRepetol.ye -= 1;}
						if (enemy instanceof RedRepetol){RedRepetol.ye -= 1;}
						if (enemy instanceof VioletRepetol){VioletRepetol.ye -= 1;}
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, enemy.myRectangle);
						}
					}
					for (Vaccine vaccine : BattleScreen.listOfVaccines){
						vaccine.moveDown(1);
						if (!b) {
							b = Intersector.intersectRectangles(playerRec, vaccine.vaccineRectangle);
						}
					}
					hex1 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x, y + Gdx.graphics.getHeight()-(int)playerRec.y + 1 + BattleScreen.resolutionProblemSolver));
					hex2 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x + (int)playerRec.getWidth(), y + Gdx.graphics.getHeight()-(int)playerRec.y + 1 + BattleScreen.resolutionProblemSolver));
					hex3 = Integer
							.toHexString(arena.getPixel(x + (int)playerRec.x +(int)playerRec.getWidth()/2, y + Gdx.graphics.getHeight()-(int)playerRec.y + 1 + BattleScreen.resolutionProblemSolver));
				}
			}
		}
		for (Orb orb : BattleScreen.listOfOrb){
			if (Intersector.intersectRectangles(playerRec, orb.getCoreRectangle())){
				orb.eaten(this);
			}
		}
		
	} 

	public void doSpecial() {
		if (mode != MSPECIAL){temp = mode;}
		mode = MSPECIAL;
		if (Gdx.input.isTouched() && special < 150){special++; state = BattleScreen.SPECIAL;
		//suara lama
		}
		else if (Gdx.input.isTouched() && special >= 150){
				special++;
				state = BattleScreen.SPECIALREADY;
				if (special == 300) {special = 150;}
				// suara bentar
		}
		else if (special >= 150 && !(Gdx.input.isTouched())){
			state = BattleScreen.DOSPECIAL;
			if (mode != MIMPERIAL){
				Rectangle tempRec = new Rectangle((Gdx.graphics.getWidth()/2)-320, (Gdx.graphics.getHeight()/2)-240, 640, 480);
				for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
					if (Intersector.intersectRectangles(tempRec, enemy.myRectangle)){
						enemy.damaged(17);
						if (enemy.isDie()){enemy.dropOrb();}
					}	
				}
			}else{
				Rectangle tempRec = new Rectangle((Gdx.graphics.getWidth()/2)-500, (Gdx.graphics.getHeight()/2)-500, 1000, 1000);
				for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
					if (Intersector.intersectRectangles(tempRec, enemy.myRectangle)){
						enemy.damaged(27);
						if (enemy.isDie()){enemy.dropOrb();}
					}	
				}				
			}
			energy = 0;
			countSpecial = 10;
			// suara duar
		}
	}

	public void doShield(){
		if (shieldOn){shieldOn = false;}
		else {shieldOn = true;}
	}

	public void doInvisible(){
		if (invisibleOn){invisibleOn = false;}
		else {invisibleOn = true;}
	}

	public void doBelumTahu(){
		belumTahuOn = true;
	}

	public void doSpecial2(){
		
	}
	
	public void doPunch() {
		hit = false;
		if(punch < 15){punch++;}
		else{		
			punch = 0;
			if(Gdx.input.getX() <= Gdx.graphics.getWidth()/2){
				face = BattleScreen.LEFT;
				if (mode == MIMPERIAL){
					punchArea.set((Gdx.graphics.getWidth()/2)-150,(Gdx.graphics.getHeight()-60)/2-80,150,160);
				}else{
					punchArea.set((Gdx.graphics.getWidth()/2)-46,(Gdx.graphics.getHeight()-60)/2-28,45,56);
				}
			}
			else {
				face = BattleScreen.RIGHT;
				if (mode == MIMPERIAL){
					punchArea.set((Gdx.graphics.getWidth()/2)+1,(Gdx.graphics.getHeight()-60)/2-80,150,160);
				}else{
					punchArea.set((Gdx.graphics.getWidth()/2)+1,(Gdx.graphics.getHeight()-60)/2-28,45,56);
				}
			}
			for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
				if (Intersector.intersectRectangles(punchArea, enemy.myRectangle)){
					enemy.damaged();
					if (mode == MIMPERIAL){
						enemy.damaged();
						enemy.damaged();
					}
					if (enemy.isDie()){enemy.dropOrb();}
					hit = true;
				}	
			}
			for (Vaccine vaccine : BattleScreen.listOfVaccines){
				if (Intersector.intersectRectangles(punchArea, vaccine.vaccineRectangle)){
					vaccine.free();
				}
			}
		}
		state = BattleScreen.PUNCH;
		
	}
	
	public void doLaser() {
		if (laser < 15) {
			laser++;
		} else {
			state = BattleScreen.LASER;
			if (Gdx.input.getX() >= ((Gdx.graphics.getWidth()/2)+5) && Math.abs(Math.asin((double)(Gdx.input.getY()-179)/Math.sqrt(((((Gdx.graphics.getWidth()/2)+5)-Gdx.input.getX())*(((Gdx.graphics.getWidth()/2)+5)-Gdx.input.getX()))+((Gdx.input.getY()-179)*(Gdx.input.getY()-179))))) <= 0.85){face = BattleScreen.RIGHT;}	
			else if(Gdx.input.getX() <= ((Gdx.graphics.getWidth()/2)-5) && Math.abs(Math.asin((double)(Gdx.input.getY()-179)/Math.sqrt(((((Gdx.graphics.getWidth()/2)-5)-Gdx.input.getX())*(((Gdx.graphics.getWidth()/2)-5)-Gdx.input.getX()))+((Gdx.input.getY()-179)*(Gdx.input.getY()-179))))) <= 0.85){face = BattleScreen.LEFT;}
			else {face = BattleScreen.FRONT;}	
			int xP;
			int yP = ((Gdx.graphics.getHeight()-60)/2)+11;
			if (face == BattleScreen.RIGHT) {xP = ((Gdx.graphics.getWidth())/2)+5;}
			else if (face == BattleScreen.LEFT) {xP = ((Gdx.graphics.getWidth())/2)-5;}
			else {xP = (Gdx.graphics.getWidth()/2);}
			for (Enemy enemy : BattleScreen.listOfEnemies.keySet()){
				if (intersectRectangleLine(xP, yP, Gdx.input.getX(), Gdx.graphics.getHeight()-Gdx.input.getY(), 128, enemy.myRectangle)){				
					enemy.lasered();
					if (enemy.isDie()){enemy.dropOrb();}
				}
				else {
					enemy.countLaser=0;
				}
			}
		}
	}

	public void cancelAct() {
		if (countSpecial == 0){
			laser = 0;
			if (special < 150){special = 0;}
			punch = 20;
			punchArea.setX(0);
			punchArea.setY(0);
			state = BattleScreen.NORMAL;
			if (special >= 150){doSpecial(); special = 0;}
		}
		else{
			countSpecial--;
			if (countSpecial == 0){mode = temp;}
			}
	}
	
	public void energyUse(int used){
		energy -= used;
	}
	
	
	public boolean isMedDroidTouched(){
		if (Gdx.graphics.getWidth()==480){return (Gdx.input.getX() >= (Gdx.graphics.getWidth()/2)-12 && Gdx.input.getX() <= (Gdx.graphics.getWidth()/2) + 12 && Gdx.input.getY() >= Gdx.graphics.getHeight()-(((Gdx.graphics.getHeight()-60)/2)+20) && Gdx.input.getY() <= Gdx.graphics.getHeight()-(((Gdx.graphics.getHeight()-60)/2)-20));}
		else if ((Gdx.graphics.getWidth()==800)){return (Gdx.input.getX() >= (Gdx.graphics.getWidth()/2)-20 && Gdx.input.getX() <= (Gdx.graphics.getWidth()/2) + 20 && Gdx.input.getY() >= Gdx.graphics.getHeight()-(((Gdx.graphics.getHeight()-60)/2)+30) && Gdx.input.getY() <= Gdx.graphics.getHeight()-(((Gdx.graphics.getHeight()-60)/2)-30));}
		else {return (Gdx.input.getX() >= (Gdx.graphics.getWidth()/2)-8 && Gdx.input.getX() <= (Gdx.graphics.getWidth()/2) + 8 && Gdx.input.getY() >= Gdx.graphics.getHeight()-(((Gdx.graphics.getHeight()-60)/2)+15) && Gdx.input.getY() <= Gdx.graphics.getHeight()-(((Gdx.graphics.getHeight()-60)/2)-15));}
	}
	

	public boolean isModeButtonTouched(){
		int tempSize;
		if (Gdx.graphics.getWidth()==480){tempSize = 60;}			
		else if (Gdx.graphics.getWidth()==800){tempSize = 100;}
		else {tempSize = 40;}
		return (Gdx.input.getY() >= Gdx.graphics.getHeight()-tempSize && Gdx.input.getY() <= Gdx.graphics.getHeight() && Gdx.input.getX() >= 0 && Gdx.input.getX() <= tempSize);
	}	
	
	public boolean isSpecialButtonTouched(){
		int tempSize;
		if (Gdx.graphics.getWidth()==480){tempSize = 60;}			
		else if (Gdx.graphics.getWidth()==800){tempSize = 100;}
		else {tempSize = 40;}
		return (Gdx.input.getY() >= Gdx.graphics.getHeight()-tempSize && Gdx.input.getY() <= Gdx.graphics.getHeight() && Gdx.input.getX() >= Gdx.graphics.getWidth()-tempSize && Gdx.input.getX() <= Gdx.graphics.getWidth());

	}
	
	public boolean intersectRectangleLine(int xP, int yP, int x2, int y2, int length, Rectangle R){
		int temp;
		int xT = xP;
		int yT = yP;
		temp = x2-xP;
		if (temp != 0) {
			while (Math.hypot((xT-xP), (yT-yP)) <= length){
				yT =  (int)Math.floor(((double)(yP-y2))/(xP-x2)*(xT-x2)+y2);
				if (xT >= R.x && xT <= R.x+R.getWidth() && yT >= R.y && yT <= R.y+R.getHeight()){return true;}
				if (x2 <= xP){xT--;}
				else {xT++;}
			}
			return false;
		}
		else {
			while (yT != y2){
				 if (xT >= R.x && xT <= (R.x + R.getWidth()) && yT >= R.y && yT <=( R.y+R.getHeight())){return true;} else
				 if (yT < y2) {yT++;} else
				 if (yT > y2) {yT--;}
			 }
			 return false;
		}
	}
	
	public void changeMode(){
		 if (mode == MPUNCH) {mode = MLASER;}
		 else if (mode == MLASER){
			if (modeShieldUnlocked){mode = MSHIELD;}
			else if (modeInvisibleUnlocked){mode = MINVISIBLE;}
			else if (modeImperialUnlocked){mode = MIMPERIAL;}
			else {mode = MPUNCH;}
		}else if (mode == MSHIELD){
			if (modeInvisibleUnlocked){mode = MINVISIBLE;}
			else if (modeImperialUnlocked){mode = MIMPERIAL;}
			else {mode = MPUNCH;}
			shieldOn = false;
		}else if (mode == MINVISIBLE){
			if (modeImperialUnlocked){mode = MIMPERIAL;}
			else {mode = MPUNCH;}
			if (invisibleOn){invisibleOn = false;}
		}else if (mode == MIMPERIAL){
			mode = MPUNCH;
		}else {mode = temp;}
		laser = 0;
	}
	
	public void rechargeEnergy(int ammount) {
		energy = energy + ammount;
		if (energy > MAX_ENERGY)
			energy = MAX_ENERGY;
	}

	public void healed(int ammount) {
		health = health + ammount;
		if (health > MAX_HP)
			health = MAX_HP;
	}

	public void damaged(int damage) {
		if (shieldOn){
			if (energy > (damage/2)){
				energy = energy - (damage/2);
				state = BattleScreen.SHIELD;
			}else {
				health -= ((damage/2)-energy)*2; 
				energy = 0; 
				shieldOn = false;
			}
		}else{
			if (health >= damage){health = health - damage;}
			else{health = 0;}
			state = BattleScreen.DAMAGE;
			countDamage = 5;
		}
	}
	
	public void checkCondition(){
		// check health, energy, requirement, decrease energy per time..hmm..
	}

	public static void main(String args[]) {
		System.out.println("Meddroid driver");
	}

	/*
	 * Accessor
	 */

	public void setEnergy(int x) {
		energy = x;
	}

	public void setHealth(int x) {
		health = x;
	}

	public void setState(int x) {
		state = x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public void setY(int x) {
		this.y = x;
	}
	
	public void setMode(int x) {
		this.mode = x;
	}
//
//	public int getEnergy() {
//		return energy;
//	}
//
//	public int getHealth() {
//		return health;
//	}
//
//	public int getState() {
//		return state;
//	}
//
//	public int x {
//		return x;
//	}
//
//	public int y {
//		return y;
//	}
//	
//	public int getFace() {
//		return face;
//	}
//
//	public int getSpecial() {
//		return special;
//	}	
//
//	public int getCountSpecial() {
//		return countSpecial;
//	}	
//	
//	public int getCountDamage() {
//		return countDamage;
//	}	

	public void decCountDamage() {
		countDamage--;
	}	
	
//	public Rectangle getRectangle() {
//		return playerRec;
//	}	
//	
//	public int getMode() {
//		return mode;
//	}	
//
//	public int getTempMode() {
//		return temp;
//	}		
}
